package com.test;

import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class FiledDemo {

    public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        Class<?> clazz = obj.getClass();
        System.out.println(clazz);
        //循环所有的参数对象
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(obj);
            map.put(fieldName, value);
        }


        return map;
    }

    /*public static void main(String[] args) {
        int maxValue = Integer.MAX_VALUE;
        System.out.println(maxValue);

        Lock lock = new ReentrantLock(true);
        try {
            lock.tryLock(10, TimeUnit.SECONDS);
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }*/

/*    public static void main(String[] args) {
        Model model = new Model("2019-11-27 23:00:00", "V1.0", "svc0001", "myMethod", "SH001", "yangjl", "hef", "sh00101010010");
        try {
            Map<String, Object> stringObjectMap = objectToMap(model);
            String s = JSONObject.toJSONString(stringObjectMap);
            System.out.println(s);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }*/
}